<xsl:stylesheet version="2.0" xmlns:foo="http://something" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:import href="/apps/engine/utils/translate_fct.xsl"/>
	<xsl:variable name="dict" select="doc('input:translation')/translation"/>
	<xsl:template match="/">
		<content>
			<h1>
				<xsl:value-of select="foo:translate('Widgets Management', $dict)"/>
			</h1>
			<form class="add_form" id="install_widget" enctype="multipart/form-data" action="../action/install" method="post">
				<fieldset>
					<legend>
						<xsl:value-of select="foo:translate('Install a new widget', $dict)"/>
					</legend>

					<input name="action" type="hidden" value="install"/>
					<div class="form_line">
						<input name="widget" class="file" id="widget_file" type="file"/>
					</div>
					<div class="form_line">
						<label for="category">
							<xsl:value-of select="foo:translate('Category', $dict)"/> : </label>
						<select name="category" id="category">
							<option value="0">
								<xsl:value-of select="foo:translate('None', $dict)"/>
							</option>

							<xsl:apply-templates mode="cat_option" select="/list/category"/>

						</select>
					</div>

					<div class="submit">
						<input class="button" type="submit" value="{foo:translate('Install', $dict)}"/>
						<input class="button" type="reset" value="{foo:translate('Cancel', $dict)}"/>
					</div>
				</fieldset>
			</form>
			<xsl:apply-templates select="/list/category"/>
		</content>
	</xsl:template>
	<xsl:template mode="cat_option" match="category">
		<xsl:if test="position() &gt; 1">
			<option value='{./@id}'>
				<xsl:value-of select="name"/>
			</option>
		</xsl:if>
	</xsl:template>
	<xsl:template match="category">
		<h2>
			<xsl:choose>
				<xsl:when test="exists(@id)">
					<xsl:value-of select="name"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="foo:translate('Widgets without category', $dict)"/>
				</xsl:otherwise>
			</xsl:choose>
		</h2>
		<xsl:apply-templates select="widget"/>
	</xsl:template>
	<xsl:template match="widget">
		<div>
			<xsl:attribute name="class">item <xsl:if test="(position() mod 2)= 0">even</xsl:if>
				<xsl:if test="(position() mod 2)!= 0">odd</xsl:if>
			</xsl:attribute>
			<div class="name">
				<xsl:value-of select="name"/>
			</div>
			<div class="control">
				<a href="#" id="v_{@id}" class="visibleOption control controlImage" title="{foo:translate('Show/Hide this Widget', $dict)}">
					<img alt="{foo:translate('Show/Hide this Widget', $dict)}">
						<xsl:attribute name="src">../../views/img/admin-widgets-<xsl:choose>
								<xsl:when test="visible = 1">visible</xsl:when>
								<xsl:otherwise>invisible</xsl:otherwise>
							</xsl:choose>.png</xsl:attribute>
					</img>
				</a>
				<a href="#" id="a_{@id}" class="authenticationOption control controlImage" title="{foo:translate('Authentication', $dict)}">
					<img alt="{foo:translate('Authentication', $dict)}">
						<xsl:attribute name="src">../../views/img/admin-widgets-<xsl:choose>
								<xsl:when test="authkey = ''">greykey</xsl:when>
								<xsl:otherwise>key</xsl:otherwise>
							</xsl:choose>.png</xsl:attribute>
					</img>
				</a>
				<a href="#" id="e_{@id}" class="editOption control controlImage" title="{foo:translate('Edit Widget', $dict)}">
					<img alt="{foo:translate('Edit Widget', $dict)}" src="../../views/img/admin-widgets-edit.png"/>
				</a>
				<a href="#" id="d_{@id}" class="deleteOption control controlImage" title="{foo:translate('Delete Widget', $dict)}">
					<img alt="{foo:translate('Delete Widget', $dict)}" src="../../views/img/admin-widgets-delete.png"/>
				</a>
			</div>
		</div>
		<div id="visibilityContainer_{@id}" class="visibility container" style="display: none;">
			<form class="form_container" action="../action/toggleVisibility" method="post">
				<div class="edit_message">
					<xsl:if test="visible = 1">
						<xsl:value-of select="foo:translate(concat('Are you sure you want to make the widget ''',name,''' invisible ?'), $dict)"/>
					</xsl:if>
					<xsl:if test="visible != 1">
						<xsl:value-of select="foo:translate(concat('Are you sure you want to make the widget ''',name,''' visible ?'), $dict)"/>
					</xsl:if>
				</div>
				<input name="action" type="hidden" value="visibility"/>
				<input name="widget" type="hidden" value="{@id}"/>

				<input class="button" type="submit" value="{foo:translate('Yes', $dict)}"/>
				<input class="button" type="reset" value="{foo:translate('Cancel', $dict)}"/>
			</form>
		</div>
		<div id="authenticationContainer_{@id}" class="authentication container" style="display: none;">
			<form class="form_container" action="../../index.php/admin/toggleVisibility" method="post">
				<xsl:if test="authkey != ''">
					<div class="edit_message">
						<xsl:value-of select="foo:translate(concat('Widget authentication system for widget ''',name,'''.'), $dict)"/>
					</div>
					<div class="edit_message">
						<xsl:value-of select="foo:translate('Secret key', $dict)"/> : <xsl:value-of select="authkey"/>
					</div>
				</xsl:if>
				<xsl:if test="authkey = ''">
					<div class="edit_message">
						<xsl:value-of select="foo:translate(concat('Widget authentication system for widget ''',name,''' is not enabled.'), $dict)"/>
					</div>
				</xsl:if>
				<input class="button" type="reset" value="{foo:translate('Close', $dict)}"/>
			</form>
		</div>
		<div id='editContainer_{@id}' class='edit container' style='display: none;'>
			<form class="form_container" enctype="multipart/form-data" action="../action/edit" method="post">
				<div class="edit_message">
					<xsl:value-of select="foo:translate(concat('Upload new widget or manifest for widget ''',name,'''.'), $dict)"/>:</div>
				<input name="action" type="hidden" value="edit"/>
				<input name="widget" type="hidden" value="{@id}"/>
				<div class="form_line">
					<input name="widgetFile" type="file"/>
				</div>
				<div class="form_line">
					<label>
						<xsl:value-of select="foo:translate('Category', $dict)"/>
					</label>: <select name="category">
						<option value="0">
							<xsl:value-of select="foo:translate('None', $dict)"/>
						</option>

						<xsl:apply-templates mode="cat_option" select="/list/category"/>

					</select>
				</div>
				<input class="button" type="submit" value="{foo:translate('Edit', $dict)}"/>
				<input class="button" type="reset" value="{foo:translate('Cancel', $dict)}"/>
			</form>
		</div>
		<div id="deleteContainer_{@id}" class="delete container" style="display: none;">
			<form class="form_container" action="../action/delete" method="post">
				<div class="form_line">
					<xsl:value-of select="foo:translate(concat('Are you sure you want to delete the widget ''',name,''' ?'), $dict)"/>
				</div>

				<input name="action" type="hidden" value="delete"/>
				<input name="widget" type="hidden" value="{@id}"/>
				<input class="button" type="submit" value="{foo:translate('Delete', $dict)}"/>
				<input class="button" type="reset" value="{foo:translate('Cancel', $dict)}"/>
			</form>
		</div>
		<!--!!! missing integration  - subsciption !!!-->
	</xsl:template>

</xsl:stylesheet>